﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    public class Solution17
    {
        public int MaxSubArray(int[] nums)
        {
            if (nums.Length==0)
            {
                return 0;
            }
            if (nums.Length==1)
            {
                return nums[0];
            }
            int max = int.MinValue;
            int sum;
            for (int i = 0; i < nums.Length; i++)
            {
                sum = 0;
                for (int j = i; j < nums.Length; j++)
                {
                    sum += nums[j];
                    if (sum>max)
                    {
                        max = sum;
                    }
                }
            }
            return max;
        }
    }
}
